<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="" prop="tableName">
        <el-input
          v-model="queryParams.tableName"
          placeholder="请输入表名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="" prop="sqlTableName">
        <el-input
          v-model="queryParams.sqlTableName"
          placeholder="请输入数据库表名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="businessName">
        <el-select
          v-model="queryParams.businessName"
          clearable
          filterable
          placeholder="业务名称"
        >
          <el-option
            v-for="item in BusinessNameList"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
        <!-- <el-input
          v-model="queryParams.businessName"
          placeholder="业务名称"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
      </el-form-item>
      <!-- <el-form-item label="" prop="indexOfSql">
        <el-input
          v-model="queryParams.indexOfSql"
          placeholder="请输入sql索引"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="dateField">
        <el-input
          v-model="queryParams.dateField"
          placeholder="请输入目标表日期字段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="" prop="planStartDate">
        <el-date-picker
          clearable
          v-model="queryParams.planStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择计划开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="" prop="planEndDate">
        <el-date-picker
          clearable
          v-model="queryParams.planEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择计划结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="" prop="actualStartDate">
        <el-date-picker
          clearable
          v-model="queryParams.actualStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择实际开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="" prop="actualEndDate">
        <el-date-picker
          clearable
          v-model="queryParams.actualEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择实际结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="" prop="updateMode">
        <el-input
          v-model="queryParams.updateMode"
          placeholder="请输入更新方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="remark">
        <el-select
          v-model="queryParams.remark"
          clearable
          filterable
          placeholder="备注筛选列表"
        >
          <el-option
            v-for="item in RemarkList"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
        <!-- <el-input
          v-model="queryParams.businessName"
          placeholder="业务名称"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
      <br />
      <el-form-item label="数据流入类型" label-width="120">
        <el-radio-group
          v-model="queryParams.dateInType"
          size="small"
          fill="#66b1ff"
          @change="getList"
        >
          <el-radio :label="null">所有记录</el-radio>
          <el-radio :label="'table'">table</el-radio>
          <el-radio :label="'excel'">excel</el-radio>
          <el-radio :label="'api'">api</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['conf:BiTableRelationshipConfig:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['conf:BiTableRelationshipConfig:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['conf:BiTableRelationshipConfig:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['conf:BiTableRelationshipConfig:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          >同步</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button plain size="mini" @click="pickEXCELID"
          >选择EXCELID</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="BiTableRelationshipConfigList"
      @selection-change="handleSelectionChange"
      :height="650"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="业务名称" align="center" prop="businessName" />
      <el-table-column label="数据流入类型" align="center" prop="dateInType" />
      <el-table-column label="sql索引" align="center" prop="indexOfSql">
        <template v-slot="scope">
          <span
            style="
              color: rgb(37, 137, 255);
              cursor: pointer;
              text-decoration: underline;
              font-weight: bold;
            "
            @click="selectformisNew(scope.row)"
            >{{ scope.row.indexOfSql }}</span
          >
        </template></el-table-column
      >
      <el-table-column
        label="源表日期字段"
        align="center"
        prop="sourceDateField"
      />
      <el-table-column label="目标表日期字段" align="center" prop="dateField" />

      <el-table-column label="计划开始时间" align="center" prop="planStartDate">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planStartDate, "{y}-{m}-{d}") }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="计划结束时间" align="center" prop="planEndDate">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planEndDate, "{y}-{m}-{d}") }}</span>
        </template> -->
      </el-table-column>
      <el-table-column
        label="实际开始时间"
        align="center"
        prop="actualStartDate"
      >
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualStartDate, "{y}-{m}-{d}") }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="实际结束时间" align="center" prop="actualEndDate">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualEndDate, "{y}-{m}-{d}") }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="打标规则" align="center" prop="actualEndDate">
        <template v-slot="scope">
          <span
            style="
              color: rgb(37, 137, 255);
              cursor: pointer;
              text-decoration: underline;
              font-weight: bold;
            "
            @click="handleBiruletag(scope.row)"
          >
            打标规则
          </span>
        </template>
      </el-table-column>
      <el-table-column label="启用打标" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isEffective"
            active-value="0"
            inactive-value="1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="逻辑处理" align="center" prop="logicalProcess" />
      <el-table-column label="启用逻辑处理" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isLogicProcessed"
            active-value="0"
            inactive-value="1"
            @change="handleisLogicProcessed(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="更新方式" align="center" prop="updateMode">
        <template v-slot="scope">
          <span
            v-if="scope.row.updateMode != 'Overwrite'"
            style="
              color: rgb(37, 137, 255);
              cursor: pointer;
              text-decoration: underline;
              font-weight: bold;
            "
            @click="opentagkey(scope.row)"
          >
            {{ scope.row.updateMode }}
          </span>
          <span v-else>{{ scope.row.updateMode }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="数据输出类型"
        align="center"
        prop="dataOutputType"
      />

      <el-table-column label="数据库表名" align="center" prop="sqlTableName">
        <template v-slot="scope">
          <span
            style="
              color: rgb(37, 137, 255);
              cursor: pointer;
              text-decoration: underline;
              font-weight: bold;
            "
            @click="selectsqlTableName(scope.row)"
            >{{ scope.row.sqlTableName }}</span
          >
        </template></el-table-column
      >
      <el-table-column label="表名" align="center" prop="tableName" />

      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['conf:BiTableRelationshipConfig:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['conf:BiTableRelationshipConfig:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改BI关系配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="数据流入类型" prop="dateInType">
          <!-- <el-input v-model="form.dateInType" placeholder="请输入数据流入类型" /> -->
          <el-select
            v-model="form.dateInType"
            clearable
            filterable
            allow-create
            placeholder="请输入数据流入类型"
          >
            <el-option
              v-for="item in dateInTypeList"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据输出类型" prop="dataOutputType">
          <!-- <el-input v-model="form.dataOutputType" placeholder="请输入数据输出类型" /> -->
          <el-select
            v-model="form.dataOutputType"
            clearable
            filterable
            allow-create
            placeholder="请输入数据输出类型"
          >
            <el-option
              v-for="item in dataOutputTypeList"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="表名" prop="tableName">
          <!-- <el-input v-model="form.tableName" placeholder="请输入表名" /> -->
          <el-select
            v-model="form.tableName"
            clearable
            filterable
            remote
            :remote-method="getDatacomment"
            placeholder="请输入表名"
            allow-create
            @change="changetableName"
          >
            <el-option
              v-for="item in tablecomment"
              :key="item.comment"
              :label="`${item.comment}`"
              :value="item.comment"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据库表名" prop="sqlTableName">
          <!-- <el-input
            v-model="form.sqlTableName"
            placeholder="请输入数据库表名"
          /> -->
          <el-select
            v-model="form.sqlTableName"
            clearable
            filterable
            remote
            :remote-method="gettableName"
            placeholder="数据库表名"
            allow-create
            @change="changesqlTableName"
          >
            <el-option
              v-for="item in tablecomment"
              :key="item.tableName"
              :label="`${item.tableName}`"
              :value="item.tableName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="业务名称" prop="businessName">
          <el-input
            style="width: 250px"
            v-model="form.businessName"
            placeholder="业务名称"
            clearable
          />
        </el-form-item>

        <el-form-item label="目标表日期字段" prop="dateField" label-width="130">
          <!-- <el-input v-model="form.dateField" placeholder="请输入日期字段" /> -->
          <!-- <el-select
            v-model="form.dateField"
            clearable
            filterable
            allow-create
            placeholder="请输入日期字段"
          >
            <el-option
              v-for="item in dateFieldoptions"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select> -->
          <el-select
            v-model="form.dateField"
            clearable
            filterable
            placeholder="请输入目标表日期字段"
            @focus="selectfieldNames(form.sqlTableName)"
            allow-create
          >
            <el-option
              v-for="item in dateFieldoptions"
              :key="item.columnName"
              :label="`${item.comment}`"
              :value="item.columnName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="sql索引"
          prop="indexOfSql"
          v-if="form.dateInType != 'excel'"
        >
          <el-input
            style="width: 200px"
            v-model="form.indexOfSql"
            placeholder="请输入sql索引"
          />
          <el-button @click="selectindexOfSql(form)" size="mini">
            Sql配置
          </el-button>
        </el-form-item>
        <el-form-item
          label="源表日期字段"
          prop="sourceDateField"
          v-if="form.dateInType != 'excel'"
        >
          <el-select
            v-model="form.sourceDateField"
            clearable
            filterable
            placeholder="请输入源表日期字段"
            @focus="selectsourceDateField(form.indexOfSql)"
            allow-create
          >
            <el-option
              v-for="item in sourceDateFieldList"
              :key="item.columnName"
              :label="`${item.comment}`"
              :value="item.columnName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="计划开始时间"
          prop="planStartDate"
          v-if="form.dateInType != 'excel'"
        >
          <el-date-picker
            clearable
            v-model="form.planStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划开始时间"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="计划结束时间"
          prop="planEndDate"
          v-if="form.dateInType != 'excel'"
        >
          <el-date-picker
            clearable
            v-model="form.planEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item
          label="实际开始时间"
          prop="actualStartDate"
          v-if="form.dateInType != 'excel'"
        >
          <el-date-picker
            clearable
            v-model="form.actualStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="实际结束时间"
          prop="actualEndDate"
          v-if="form.dateInType != 'excel'"
        >
          <el-date-picker
            clearable
            v-model="form.actualEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际结束时间"
          >
          </el-date-picker>
        </el-form-item> -->
        <el-form-item label="更新方式" prop="updateMode">
          <!-- <el-input v-model="form.updateMode" placeholder="请输入更新方式" /> -->
          <el-select
            v-model="form.updateMode"
            clearable
            placeholder="请输入更新方式"
          >
            <el-option
              v-for="(val, i) in columnTypeList"
              :key="i"
              :label="val"
              :value="val"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="逻辑处理" prop="logicalProcess">
          <el-input
            v-model="form.logicalProcess"
            placeholder="请输入逻辑处理"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- <el-dialog
      :visible.sync="openindexOfSql"
      width="600px"
      append-to-body
      v-if="openindexOfSql"
    >
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleindexOfSql"
            v-show="BtnindexOfSql"
            >添加到索引</el-button
          >
        </el-col>
      </el-row>

      <el-table
        :data="previewSql"
        :height="300"
        @selection-change="handleSelectionChangeindexOfSql"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column width="350" label="预览sql" align="center" prop="">
          <template slot-scope="scope">
            {{ scope.row.previewSql }}
            
          </template>
        </el-table-column>
        <el-table-column label="说明" align="center" prop="description" />
      </el-table>
    </el-dialog> -->

    <el-dialog
      :visible.sync="openindexOfSql"
      width="1500px"
      append-to-body
      v-if="openindexOfSql"
    >
      <div class="el-dialog-div">
        <component
          :is="'BiSqlFirstField'"
          :row="row"
          @handleSqlId="handleindexOfSql"
        ></component>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="openInfo"
      width="1500px"
      append-to-body
      v-if="openInfo"
    >
      <div class="el-dialog-div">
        <component
          :is="'BiSqlFirstField'"
          :row="row"
          @handleSqlId="handleSqlId"
        ></component>
      </div>
    </el-dialog>

    <el-dialog
      append-to-body
      :visible.sync="openSysTableData"
      width="1800px"
      v-if="openSysTableData"
    >
      <SysTableData :rowQuery="row" />
    </el-dialog>

    <el-dialog
      :visible.sync="tagkeyVisible"
      width="700px"
      append-to-body
      v-if="tagkeyVisible"
    >
      <el-card style="margin-bottom: 16px">
        <div slot="header">
          删除条件
          <!-- <span
            >采购单号:{{ this.list[0].purchaseOrderNumber }},sku:{{
              this.list[0].sku
            }}</span
          > -->
        </div>
        <div class="el-dialog-div">
          <el-form :model="formData" :inline="true">
            <!-- <el-form-item label="采购单号:">
              {{ this.list[0].purchaseOrderNumber }}
            </el-form-item>
            <el-form-item label="sku:">
              {{ this.list[0].sku }}
            </el-form-item>
            <el-row>
              <el-form-item label="方案编码">
                <el-input v-model="strategyCode" placeholder="请输入方案编码" />
              </el-form-item>
              <el-button
                type="primary"
                plain
                size="mini"
                @click="openCode = true"
              >
                +
              </el-button>
            </el-row> -->
            <!-- <el-row>
              <el-form-item
                style="width: 200px"
                label="店铺名称"
              ></el-form-item>
              <el-form-item
                style="width: 100px"
                label="计划分配数量"
              ></el-form-item>
            </el-row> -->
            <el-form-item
              v-for="(item, index) in formData.libraryIdList"
              :key="index"
            >
              <!-- <el-input
              style="width: 150px"
              v-model="item.storeName"
              placeholder="店铺名称"
            ></el-input> -->
              <el-select
                :disabled="item.isEdit"
                style="width: 150px"
                v-model="item.fieldName"
                placeholder="请输入字段"
                clearable
                filterable
                allow-create
              >
                <el-option
                  v-for="dict in tableNameList"
                  :key="dict.field_name"
                  :label="dict.comment"
                  :value="dict.field_name"
                />
              </el-select>
              <!-- <el-input
              style="width: 150px"
              v-model="item.field_name"
              placeholder="请输入字段值"
            ></el-input> -->
              <el-select
                v-model="item.operatorValue"
                style="width: 100px"
                placeholder="操作符"
              >
                <el-option label="=" value="=" />
                <el-option label="!=" value="!=" />
                <el-option label=">" value=">" />
                <el-option label=">=" value=">=" />
                <el-option label="<" value="<" />
                <el-option label="<=" value="<=" />
              </el-select>
              <el-input
                style="width: 200px"
                v-model="item.compareValue"
                placeholder="比较值"
              ></el-input>

              <span
                v-if="formData.libraryIdList.length > 0"
                style="margin-left: 5px"
              >
                <el-button type="primary" size="mini" @click="addLibraryIdList"
                  >新增</el-button
                >
                <el-button
                  type="danger"
                  size="mini"
                  @click="delRow(item, index)"
                  >删除</el-button
                >
              </span>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitformData">确 定</el-button>
        <el-button @click="canceltagkeyVisible">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="openForBiruletag"
      width="1500px"
      append-to-body
      v-if="openForBiruletag"
    >
      <div class="el-dialog-div">
        <component :is="'Biruletag'" :sqlTableName="sqlTableName"></component>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import SysTableData from "@/views/conf/SysTableData/index.vue";
import BiSqlFirstField from "@/views/conf/BiSqlFirstField/index.vue";
import {
  listBiAbnormalRule,
  getBiAbnormalRule,
  delBiAbnormalRule,
  addBiAbnormalRule,
  updateBiAbnormalRule,
  checkAbnormalByIdS,
} from "@/api/abnormal/BiAbnormalRule";
import {
  listBiTableRelationshipConfig,
  getBiTableRelationshipConfig,
  delBiTableRelationshipConfig,
  addBiTableRelationshipConfig,
  updateBiTableRelationshipConfig,
  processData,
  selectTableRelationshipConfigFields,
  selectBusinessNameList,
  selectRemarkList,
} from "@/api/conf/BiTableRelationshipConfig";
import {
  listBiSqlFirstField,
  getBiSqlFirstField,
  delBiSqlFirstField,
  addBiSqlFirstField,
  updateBiSqlFirstField,
  buildSelectSQLs,
} from "@/api/conf/BiSqlFirstField";
import {
  selectTableFields,
  selectTableNameList,
} from "@/api/conf/SysTableField";
import {
  RuleTagger,
  getTablefieldsWithComments,
} from "@/api/conf/BiRuleSpecifications";
import {
  listBiDeleteCondition,
  delBiDeleteCondition,
  insertData,
} from "@/api/conf/BiDeleteCondition";
import Biruletag from "@/views/conf/biruletag/Biruletag.vue";
export default {
  name: "BiTableRelationshipConfig",
  props: {
    id: {
      type: Number,
      default: 0,
    },
    tableName: {
      type: String,
      default: null,
    },
  },
  components: {
    BiSqlFirstField,
    SysTableData,
    Biruletag,
  },
  data() {
    return {
      RemarkList: [],
      BusinessNameList: [],
      openForBiruletag: false,
      sqlTableName: "",
      tableNameList: [],
      tagkeyVisible: false,
      formData: {
        libraryIdList: [{ fieldName: "", operatorValue: "", compareValue: "" }],
      },

      sourceDateFieldList: [],
      openSysTableData: false,
      rowInfo: {},
      row: {},
      openInfo: false,
      idsindexOfSql: [],
      BtnindexOfSql: false,
      tablecomment: [],
      previewSql: [],
      openindexOfSql: false,
      dateFieldoptions: [],
      columnTypeList: ["DeleteUpdate", "Overwrite"],
      dateInTypeList: ["table", "excel", "api"],
      dataOutputTypeList: ["table", "api"],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // BI关系配置表格数据
      BiTableRelationshipConfigList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tableName: null,
        sqlTableName: null,
        indexOfSql: null,
        dateInType: null,
        dataOutputType: null,
        dateField: null,
        planStartDate: null,
        planEndDate: null,
        actualStartDate: null,
        actualEndDate: null,
        updateMode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        tableName: [
          { required: true, message: "表名不能为空", trigger: "blur" },
        ],
        sqlTableName: [
          { required: true, message: "数据库表名不能为空", trigger: "blur" },
        ],
        indexOfSql: [
          { required: true, message: "sql索引不能为空", trigger: "blur" },
        ],
        dateInType: [
          {
            required: true,
            message: "数据流入类型不能为空",
            trigger: "change",
          },
        ],
        dataOutputType: [
          {
            required: true,
            message: "数据输出类型不能为空",
            trigger: "change",
          },
        ],
        dateField: [
          {
            required: true,
            message: "目标表日期字段不能为空",
            trigger: "blur",
          },
        ],
        planStartDate: [
          { required: true, message: "计划开始时间不能为空", trigger: "blur" },
        ],
        planEndDate: [
          { required: true, message: "计划结束时间不能为空", trigger: "blur" },
        ],
        updateMode: [
          { required: true, message: "更新方式不能为空", trigger: "blur" },
        ],
      },
    };
  },
  watch: {
    id: {
      handler: function (newnew, oldold) {
        console.log("newnew", newnew);
        if (newnew) {
          this.queryParams.id = newnew;
          // this.queryParams.dateInType = "excel";
          // this.form.id=newnew

          this.getList();
          // this.gettableNameList();
        }
      },
      deep: true,
      immediate: true,
    },
    tableName: {
      handler: function (newnew, oldold) {
        this.queryParams.sqlTableName = this.tableName;
        this.getList();
      },
      deep: true,
      immediate: true,
    },
  },
  created() {
    this.getList();
    selectBusinessNameList().then((response) => {
      this.BusinessNameList = response;
    });
    selectRemarkList().then((response) => {
      this.RemarkList = response;
    });
  },
  methods: {
    getselectBusinessNameList() {},

    opentagkey(row) {
      // listShop({
      //   strategyCode: this.row.strategyCode,
      //   businessType: "priority",
      // }).then((response) => {
      //   let list = [{ storeName: "", plannedAllocationQty: "" }];
      //   if (response.rows.length > 0) {
      //     list = [];
      //     response.rows.forEach((item) => {
      //       list.push({
      //         storeName: item.storeName,
      //         plannedAllocationQty: item.plannedAllocationQty,
      //       });
      //     });
      //   }
      //   // this.cols
      //   this.formData.libraryIdList = list;
      // });
      // if (this.list.length != 1) {
      //   this.$modal.msgError("只勾选一条记录");
      //   return;
      // }

      let obj = {
        pageNum: 1,
        pageSize: 100,
        biRelationshipTableId: row.id,
      };
      listBiDeleteCondition(obj).then((response) => {
        if (response.rows.length > 0) {
          this.formData.libraryIdList = [];
          response.rows.forEach((item) => {
            this.formData.libraryIdList.push({ ...item, isEdit: true });
          });
        } else {
          this.formData.libraryIdList = [
            {
              fieldName: "",
              operatorValue: "",
              compareValue: "",
              isEdit: false,
            },
          ];
        }
      });
      if (!row.sqlTableName) {
        return;
      }
      getTablefieldsWithComments({
        tableName: row.sqlTableName,
      }).then((response) => {
        this.tableNameList = [];
        this.tableNameList = response;
      });
      this.rowInfo = row;
      this.tagkeyVisible = true;
    },
    submitformData() {
      const hasEmptyProductNo = this.formData.libraryIdList.some(
        (product) => product.fieldName == ""
      );
      if (hasEmptyProductNo) {
        this.$modal.msgError("检查字段是否为空");
        return;
      }
      this.formData.libraryIdList.forEach((item) => {
        item.tableName = this.rowInfo.sqlTableName;
        item.biRelationshipTableId = this.rowInfo.id;
        // item.strategyCode = this.strategyCode;
      });
      insertData(this.formData.libraryIdList).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess("新增成功");
          this.tagkeyVisible = false;
          this.getList();
        }
      });
    },
    // 取消按钮
    canceltagkeyVisible() {
      this.tagkeyVisible = false;
    },
    //添加库存名称
    addLibraryIdList() {
      this.formData.libraryIdList.push({
        fieldName: "",
        operatorValue: "",
        compareValue: "",
        isEdit: false,
      });
    },
    //库存名称删除
    delRow(item, index) {
      if (this.formData.libraryIdList.length > 0) {
        this.formData.libraryIdList.splice(index, 1);
        // if (!item.isEdit) {

        // } else {
        //   const ids = item.id;
        //   this.$modal
        //     .confirm('是否确认删除删除更新条件编号为"' + ids + '"的数据项？')
        //     .then(function () {
        //       return delBiDeleteCondition(ids);
        //     })
        //     .then(() => {
        //       // this.getList();
        //       this.$modal.msgSuccess("删除成功");
        //     })
        //     .catch(() => {});
        // }
      } else {
        this.$message.warning("至少选择一项");
      }
    },

    //滑块
    handleisLogicProcessed(row) {
      let text = row.isLogicProcessed === "0" ? "启用" : "停用";
      this.$modal
        .confirm('确认要"' + text + '"生效吗？')
        .then(function () {
          return updateBiTableRelationshipConfig(row);
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.isLogicProcessed = row.isLogicProcessed === "0" ? "1" : "0";
        });
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.isEffective === "0" ? "启用" : "停用";
      this.$modal
        .confirm('确认要"' + text + '"生效吗？')
        .then(function () {
          return updateBiTableRelationshipConfig(row);
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.isEffective = row.isEffective === "0" ? "1" : "0";
        });
    },
    pickEXCELID() {
      // if (!this.queryParams.sqlId) {
      //   this.$modal.msgError("这个按钮是对外的");
      //   return;
      // }
      if (this.ids.length != 1) {
        this.$modal.msgError("请只选择一条数据");
        return;
      } else {
        this.$emit("pickEXCELID", this.ids[0]);
      }
    },
    selectsqlTableName(row) {
      // this.rowInfo = row;
      this.row = row;
      this.openSysTableData = true;
    },
    //form里的
    handleindexOfSql(id) {
      this.form.indexOfSql = id;
      this.openindexOfSql = false;
    },
    selectsourceDateField(indexOfSql) {
      selectTableRelationshipConfigFields(indexOfSql).then((response) => {
        this.sourceDateFieldList = response.data;
      });
    },
    selectindexOfSql(row) {
      this.row = { id: row.id, sqlId: row.indexOfSql };
      this.openindexOfSql = true;
    },

    //table里的
    handleSqlId(id) {
      delete this.rowInfo.indexOfSql;
      this.form = { ...this.rowInfo, indexOfSql: id };
      updateBiTableRelationshipConfig(this.form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.openInfo = false;
        this.getList();
      });
    },
    selectformisNew(row) {
      this.rowInfo = row;
      this.row = { id: row.id, sqlId: row.indexOfSql };
      this.openInfo = true;
    },

    selectfieldNames(tableName) {
      if (!tableName) {
        return;
      }
      selectTableFields({ tableName: tableName }).then((response) => {
        this.dateFieldoptions = response.map((item) => ({
          columnName: item.columnName,
          comment: item.comment ? item.comment : item.columnName,
        }));
      });
    },
    changesqlTableName(value) {
      const selectedOption = this.tablecomment.find(
        (option) => option.tableName === value
      );
      console.log(JSON.stringify(selectedOption)); // 这里就是整个选项对象
      this.form.tableName = selectedOption.comment;
      this.form.dateField = "";
    },
    changetableName(value) {
      const selectedOption = this.tablecomment.find(
        (option) => option.comment === value
      );
      console.log(JSON.stringify(selectedOption)); // 这里就是整个选项对象
      this.form.sqlTableName = selectedOption.tableName;
      this.form.dateField = "";
    },
    getDatacomment(key) {
      selectTableNameList({ comment: key }).then((response) => {
        this.tablecomment = response;
      });
    },
    gettableName(key) {
      selectTableNameList({ tableName: key }).then((response) => {
        this.tablecomment = response;
      });
    },

    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载数据，请稍候！");
    },
    /** 刷新缓存按钮操作 Warning*/
    handleRefreshCache() {
      if (this.ids.length <= 0) {
        this.$modal.msgError("请至少选择一条数据");
        return;
      }

      this.openLoading();
      processData(this.ids).then(() => {
        this.$modal.closeLoading();
        this.$modal.msgSuccess("数据已同步");
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    /** 查询BI关系配置列表 */
    getList() {
      this.loading = true;
      listBiAbnormalRule(this.queryParams).then((response) => {
        this.BiTableRelationshipConfigList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tableName: null,
        sqlTableName: null,
        indexOfSql: null,
        dateInType: null,
        dataOutputType: null,
        dateField: null,
        planStartDate: null,
        planEndDate: null,
        actualStartDate: null,
        actualEndDate: null,
        updateMode: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {};
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加BI关系配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiTableRelationshipConfig(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改BI关系配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiTableRelationshipConfig(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiTableRelationshipConfig(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除BI关系配置编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiTableRelationshipConfig(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "conf/BiTableRelationshipConfig/export",
        {
          ...this.queryParams,
        },
        `BiTableRelationshipConfig_${new Date().getTime()}.xlsx`
      );
    },

    handleBiruletag(row) {
      this.sqlTableName = row.sqlTableName;
      this.openForBiruletag = true;
    },
    handleGo(path, row) {
      this.$router.push({
        path: path,
        query: { tableName: row.sqlTableName },
      });
    },
  },
};
</script>
 <!-- <el-table-column label="BI关系表ID" align="center" prop="biRelationshipTableId" />
      <el-table-column label="表名" align="center" prop="tableName" />
      <el-table-column label="字段名" align="center" prop="fieldName" />
      <el-table-column label="操作符" align="center" prop="operatorValue" />
      <el-table-column label="比较值" align="center" prop="compareValue" /> -->